home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / strlink.com / STRLINK.DOC < prev    next >
Encoding:
Text File  |  1989-09-01  |  19.0 KB  |  449 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.                                     STRLINK OBJECT
  7.                                      Version 1.01
  8.                                    1 September 1989
  9.  
  10.                                    Rob Rosenberger
  11.                                   Barn Owl Software
  12.                                      P.O. Box 74
  13.                                  O'Fallon, IL  66269
  14.                                     (618) 632-7345
  15.  
  16.  
  17.                This Turbo Pascal v5.5 OOP object implements a linked list
  18.           of strings.  You no longer have to read a text file more than one
  19.           time: you can now let an OOP variable of StrLinkList type read it
  20.           into memory.  You can sort text files based on varying criteria,
  21.           remove redundant strings, etc.
  22.  
  23.                This link list of strings offers an extra added bonus.  Each
  24.           string on the list takes up only as much space as it absolutely
  25.           requires.  This is true even if you change the size of the string
  26.           after putting it on the list.  (You can always inspect the code
  27.           if you want to see how it was accomplished.)
  28.  
  29.                And because it's OOP, you can create a descendent object if
  30.           you have special needs.  If any of the code is ever updated, you
  31.           can usually upgrade to the new version ── without changing a line
  32.           of your descendent code.  (Assuming the calls themselves in the
  33.           ancestor object haven't changed, of course.)
  34.  
  35.  
  36.           UNIT NAME
  37.  
  38.  
  39.                The name of the main unit is "StrLink".  You should put this
  40.           in any program or unit of your own that needs access to variables
  41.           of type StrLinkList.
  42.  
  43.  
  44.           CONDITIONAL DIRECTIVES
  45.  
  46.  
  47.                {$IFDEF TPRO5}
  48.  
  49.                The StrLink unit can optionally use TurboPower Software's
  50.           TPRO5 toolkit.  TPRO5 offers some extra efficiency & speed for
  51.           string link lists.  If you do NOT have TPRO5, you must change the
  52.           '$' to a '.' so the proper code will compile.
  53.                I encourage you to write or call TurboPower for a brochure
  54.           about their products.  I actually pity you if you aren't using
  55.           their toolkits.  TPRO5 contains 50,000+ lines of source code in
  56.           over 30 units, and TurboPower is coming out soon with OPRO, the
  57.           Object Professional Toolkit.  You can contact TurboPower at P.O.
  58.           Box 66747, Scotts Valley, CA 95066, or call (408) 438-8608.  Be
  59.           sure to tell them I said hi.
  60.  
  61.           STRLINK OBJECT                                        Page 2 of 8
  62.  
  63.  
  64.  
  65.           USES
  66.  
  67.  
  68.                The StrLink unit USES the following units:
  69.  
  70.                     {$IFDEF TPRO5}
  71.                         TpString,
  72.                     {$ENDIF}
  73.                     Objects,
  74.                     ObjectA,
  75.                     StrObj;
  76.  
  77.                The TpString unit is supplied with the TurboPower Software
  78.           TPRO5 toolkit.  Please see the section on conditional compilation
  79.           directives for more information about this powerful toolkit.
  80.                The Objects unit is on Turbo Pascal v5.5 disk #3.  It imple-
  81.           ments the foundation of a singly linked list object.
  82.                The ObjectA unit is included in this file IF this was pulled
  83.           down from a BBS.  If it was pulled down from CompuServe, then you
  84.           must also download OBJA.ARC from BPROGA forum LIBrary 1.  ObjectA
  85.           builds on the Objects unit by offering a more powerful descendent
  86.           object for singly linked lists.
  87.                The StrObj unit is included with StrLink.  It implements the
  88.           foundation for a string object.  Each string object will take up
  89.           only as much room on the heap as it absolutely requires.
  90.  
  91.  
  92.           TYPES
  93.  
  94.  
  95.           SortedOrderType = (ForwardOrder,
  96.                              ReverseOrder,
  97.                              AscendingOrder,
  98.                              DescendingOrder);
  99.  
  100.           StrLinkList
  101.            = OBJECT(LinkList)
  102.              CurrentStrPtr     : StrObjectPtr;
  103.              UniqueStringsOnly : BOOLEAN;
  104.              SortedOrder       : SortedOrderType;
  105.              CaseMatters       : BOOLEAN;
  106.  
  107.              CONSTRUCTOR Init(UniqueStrings : BOOLEAN;
  108.                               SortSpecifier : SortedOrderType;
  109.                               IgnoreCase    : BOOLEAN);
  110.  
  111.              FUNCTION  GetSpecificString(NodePos : LONGINT) : STRING;
  112.              PROCEDURE DeleteSpecificString(NodePos : LONGINT);
  113.  
  114.              FUNCTION  ReadStrings(TheFilename : STRING) : WORD; VIRTUAL;
  115.              FUNCTION  WriteStrings(TheFilename : STRING;
  116.                                     AppendFile  : BOOLEAN) : WORD; VIRTUAL;
  117.  
  118.              FUNCTION  AddString(TheStr : STRING) : BOOLEAN;
  119.  
  120.           STRLINK OBJECT                                        Page 3 of 8
  121.  
  122.  
  123.  
  124.              PROCEDURE DeleteString(TheStr : STRING);
  125.              FUNCTION  Exists(TheStr : STRING) : BOOLEAN;
  126.              FUNCTION  ExistsSubstring(TheSubStr : STRING) : BOOLEAN;
  127.              PROCEDURE DeleteStringsWithoutSubstring(TheSubStr  : STRING;
  128.                                                      IgnoreCase : BOOLEAN);
  129.              PROCEDURE DeleteStringsWithSubstring(TheSubStr  : STRING;
  130.                                                   IgnoreCase : BOOLEAN);
  131.              PROCEDURE DeleteDuplicates;
  132.              PROCEDURE DeleteLeadNullStrings;
  133.              PROCEDURE DeleteNullStrings;
  134.              PROCEDURE DeleteTrailNullStrings;
  135.  
  136.              FUNCTION  TotalLengthOfStrings : LONGINT;
  137.  
  138.              PROCEDURE InitCurrent;
  139.              FUNCTION  CurrentString : STRING;
  140.              PROCEDURE ChangeCurrentString(NewStr : STRING);
  141.              FUNCTION  FirstString : STRING;
  142.              FUNCTION  LastString : STRING;
  143.              PROCEDURE Advance;
  144.              PROCEDURE Retreat;
  145.              FUNCTION  MoreStrings : BOOLEAN;
  146.              FUNCTION  NoMoreStrings : BOOLEAN
  147.              END;
  148.  
  149.           STRLINK OBJECT                                        Page 4 of 8
  150.  
  151.  
  152.  
  153.           PROCEDURES & FUNCTIONS
  154.  
  155.  
  156.           CONSTRUCTOR Init(UniqueStrings : BOOLEAN;
  157.                            SortSpecifier : SortedOrderType;
  158.                            IgnoreCase    : BOOLEAN);
  159.  
  160.                Initializes the StrLinkList instantiation.  UniqueStrings
  161.           dictates if the list should ignore duplicate strings.  IgnoreCase
  162.           dictates if the strings should be viewed as all uppercase, even
  163.           though they will be stored as upper/lowercase.
  164.                SortSpecifier dictates how the list is sorted.  ForwardOrder
  165.           means strings will be added to the END of the list.  This is the
  166.           same as reading a regular text file.  ReverseOrder means strings
  167.           will be added to the BEGINNING of the list.  This would be like
  168.           reading a text file backwards.  AscendingOrder dictates that the
  169.           list will be sorted in ascending order.  DescendingOrder dictates
  170.           that the list will be sorted in descending order.
  171.                The IgnoreCase boolean is important if you choose to sort
  172.           the list in ascending/descending order.  If IgnoreCase is FALSE,
  173.           "BBBB" will come before "aaaa".  When IgnoreCase is TRUE, all
  174.           strings are viewed as uppercase.  But don't worry, they're stored
  175.           exactly as they are.  IgnoreCase is important only during string
  176.           comparisons.
  177.                As a good programming practice, you should call Init() as a
  178.           function, not as a procedure.  (See TP OOP guide pp. 106-7, and
  179.           TP reference guide ch. 15, for more details.)  The boolean result
  180.           of Init(), if called as a function, is the success or failure of
  181.           the object's construction.
  182.  
  183.  
  184.           DESTRUCTOR  Done;
  185.  
  186.                This destructor is INHERITED from an ancestral object.  It
  187.           completely removes all strings from the list and frees up their
  188.           associated memory.  You must call this destructor/procedure when
  189.           you're finished with the list.  (You can "flush" the list for a
  190.           new purpose by calling Done, then calling Init once more.)
  191.  
  192.  
  193.           FUNCTION  GetSpecificString(NodePos : LONGINT) : STRING;
  194.  
  195.              This function returns a string from the StrLinkList based on
  196.           the position of a particular string in the list.  This is useful
  197.           for people who use TurboPower Software's TPRO5 TpPick unit, for
  198.           example.  The position is represented by NodePos.  This function
  199.           returns a null string if NodePos is <= 0 or if it is > the last
  200.           node on the list.  The CurrentString function will return this
  201.           string after you use this function.
  202.  
  203.           STRLINK OBJECT                                        Page 5 of 8
  204.  
  205.  
  206.  
  207.           PROCEDURE DeleteSpecificString(NodePos : LONGINT);
  208.  
  209.              This procedure deletes a string from the StrLinkList based on
  210.           the position of the string in the list, represented by NodePos.
  211.           It does nothing if NodePos is <= 0 or if it is > the last string
  212.           position on the list.  The CurrentString function points to NO
  213.           string after this call.
  214.  
  215.  
  216.           FUNCTION  ReadStrings(TheFilename : STRING) : WORD; VIRTUAL;
  217.  
  218.              Reads strings from TheFilename and adds them to the list.  The
  219.           IORESULT value is returned as the result of this function, except
  220.           in cases where the heap ceiling caves in, at which point a value
  221.           of MAXINT is returned.
  222.                This method is VIRTUAL ── you can expand on it with your own
  223.           descendent objects.
  224.  
  225.  
  226.           FUNCTION  WriteStrings(TheFilename : STRING;
  227.                                  AppendFile  : BOOLEAN) : WORD; VIRTUAL;
  228.  
  229.              Writes all strings on the list to TheFilename.  The IORESULT
  230.           value is returned as the result of this function.  AppendFile
  231.           dictates if the strings should be appended to the end of a file
  232.           if it already exists.  NOTE: the file must exist if AppendFile is
  233.           set to TRUE.
  234.                This method is VIRTUAL ── you can expand on it with your own
  235.           descendent objects.
  236.  
  237.  
  238.           FUNCTION  AddString(TheStr : STRING) : BOOLEAN;
  239.  
  240.              Adds a string to the list.  It does nothing if the string is
  241.           redundant AND UniqueStrings was TRUE when you called Init.  The
  242.           CurrentString function is undefined after calling this routine.
  243.           (It may, or may not, point to the newly added string.)
  244.                This method returns FALSE only if there is no more room on
  245.           the heap to add the new string to the list.
  246.  
  247.  
  248.           PROCEDURE DeleteString(TheStr : STRING);
  249.  
  250.              This procedure deletes the given string from the list.  It
  251.           does nothing if the string doesn't exist.  The CurrentString
  252.           function points to NO string after this call.
  253.  
  254.  
  255.           FUNCTION  Exists(TheStr : STRING) : BOOLEAN;
  256.  
  257.              Determines if the given string is on the list.  This function
  258.           is affected by the IgnoreCase declaration you specified when you
  259.           called the Init() constructor.
  260.  
  261.           STRLINK OBJECT                                        Page 6 of 8
  262.  
  263.  
  264.  
  265.           FUNCTION  ExistsSubstring(TheSubStr : STRING) : BOOLEAN;
  266.  
  267.              Similar to the Exists function, this routine determines if a
  268.           given substring is on the StrLinkList.  It searches every string
  269.           on the list until it either finds the substring inside one of the
  270.           strings, or it runs out of strings to search.  This function is
  271.           TRUE if TheSubStr is a null string and at least one string exists
  272.           on the list.
  273.                This function is affected by the IgnoreCase declaration you
  274.           specified when you called the Init() constructor.
  275.                If the result is TRUE, CurrentString will return the first
  276.           string on the list containing the given substring.
  277.  
  278.  
  279.           PROCEDURE DeleteStringsWithoutSubstring(TheSubStr  : STRING;
  280.                                                   IgnoreCase : BOOLEAN);
  281.  
  282.              This procedure deletes any string from the list that doesn't
  283.           contain the given substring.  No strings will be deleted if the
  284.           substring is a null string.  The IgnoreCase variable dictates
  285.           whether upper/lower case is relevant during the search.  (This
  286.           overrides the string comparison check you specified when you
  287.           called Init.)
  288.  
  289.  
  290.           PROCEDURE DeleteStringsWithSubstring(TheSubStr  : STRING;
  291.                                                IgnoreCase : BOOLEAN);
  292.  
  293.              This procedure deletes any string from the list that DOES
  294.           contain the given substring.  No strings will be deleted if the
  295.           substring is a null string.  The IgnoreCase variable dictates
  296.           whether upper/lower case is relevant during the search.  (This
  297.           overrides the string comparison check you specified when you
  298.           called Init.)
  299.  
  300.  
  301.           PROCEDURE DeleteDuplicates;
  302.  
  303.                This procedure deletes duplicate strings from the list.  It
  304.           does nothing if you specified unique strings during the call to
  305.           the Init procedure.  This function is affected by the IgnoreCase
  306.           declaration you specified when you called the Init() constructor.
  307.  
  308.  
  309.           PROCEDURE DeleteLeadNullStrings;
  310.  
  311.                This procedure deletes leading null strings from the list.
  312.           It's an easy way to strip out any leading blank lines from a text
  313.           file.  Null strings that exist past the first non-null string in
  314.           the list are left alone.
  315.  
  316.           STRLINK OBJECT                                        Page 7 of 8
  317.  
  318.  
  319.  
  320.           PROCEDURE DeleteNullStrings;
  321.  
  322.                This procedure deletes all null strings from the list.  It's
  323.           an easy way to delete all the blank lines from a text file you
  324.           just read from disk.
  325.  
  326.  
  327.           PROCEDURE DeleteTrailNullStrings;
  328.  
  329.                This procedure deletes trailing null strings from the list.
  330.           It's an easy way to delete blank lines from the end of a text
  331.           file you just read from disk.
  332.  
  333.  
  334.           FUNCTION  TotalLengthOfStrings : LONGINT;
  335.  
  336.                Returns the total length of the strings on the list.  This
  337.           is much faster than calculating the total length with successive
  338.           calls to LENGTH(GetCurrentString).  The CurrentString function
  339.           points to NO string after this call.
  340.  
  341.  
  342.           PROCEDURE InitCurrent;
  343.  
  344.                This function initializes the CurrentString so it returns
  345.           the first first string on the list (assuming there is at least
  346.           one string on the list).  The MoreStrings function must be used
  347.           to test if there is at least one string on the list.
  348.  
  349.  
  350.           FUNCTION  CurrentString : STRING;
  351.  
  352.                This function returns the current string pointed to in the
  353.           list.  You must use the InitCurrent procedure to set the current
  354.           string to the first string in the list.  CurrentString returns a
  355.           null string if it points to no string.  (Use the MoreStrings and
  356.           NoMoreStrings functions to determine if CurrentString points to a
  357.           string.)
  358.  
  359.  
  360.           PROCEDURE ChangeCurrentString(NewStr : STRING);
  361.  
  362.                Changes the current string to the new string.
  363.  
  364.  
  365.           FUNCTION  FirstString : STRING;
  366.  
  367.                Returns the first String in the list.  It returns a null
  368.           string if there are no strings in the list.  The CurrentString
  369.           function will also return the first string after you call this
  370.           function.
  371.  
  372.           STRLINK OBJECT                                        Page 8 of 8
  373.  
  374.  
  375.  
  376.           FUNCTION  LastString : STRING;
  377.  
  378.                Returns the last String in the list.  It returns a null
  379.           string if there are no strings in the list.  The CurrentString
  380.           function will also return the last string after you call this
  381.           function.
  382.  
  383.  
  384.           PROCEDURE Advance;
  385.  
  386.                This procedure simply moves the current string pointer to
  387.           the next string in the list.  You should use the MoreStrings or
  388.           NoMoreStrings functions to see if there is another string on the
  389.           list after making this call.
  390.  
  391.  
  392.           PROCEDURE Retreat;
  393.  
  394.                This procedure simply moves the current string pointer to
  395.           the previous string in the list.  The CurrentString function
  396.           points to NO string if you retreat past the first string on the
  397.           list.  Use the MoreStrings or NoMoreStrings functions to see if
  398.           there is another string on the list after making this call.
  399.  
  400.  
  401.           FUNCTION  MoreStrings : BOOLEAN;
  402.  
  403.                Returns TRUE or FALSE, explaining if CurrentString points to
  404.           a valid string in the list.  Should be used with the Advance and
  405.           Retreat procedures.
  406.                Special note:  MoreStrings tells you if CurrentString() is
  407.           pointing to a string RIGHT NOW.  It does not tell you if there is
  408.           another string waiting after the current string.
  409.  
  410.  
  411.           FUNCTION  NoMoreStrings : BOOLEAN;
  412.  
  413.                The opposite of the MoreStrings function.  See above.
  414.  
  415.          ----------------end-of-author's-documentation---------------
  416.  
  417.                         Software Library Information:
  418.  
  419.                    This disk copy provided as a service of
  420.  
  421.                         The Public (Software) Library
  422.  
  423.          We are not the authors of this program, nor are we associated
  424.          with the author in any way other than as a distributor of the
  425.          program in accordance with the author's terms of distribution.
  426.  
  427.          Please direct shareware payments and specific questions about
  428.          this program to the author of the program, whose name appears
  429.          elsewhere in  this documentation. If you have trouble getting
  430.          in touch with the author,  we will do whatever we can to help
  431.          you with your questions. All programs have been tested and do
  432.          run.  To report problems,  please use the form that is in the
  433.          file PROBLEM.DOC on many of our disks or in other written for-
  434.          mat with screen printouts, if possible.  The P(s)L cannot de-
  435.          bug programs over the telephone.
  436.  
  437.          Disks in the P(s)L are updated monthly, so if you did not get
  438.          this disk  directly from the P(s)L,  you should be aware that
  439.          the files in this set may no  longer be the current versions.
  440.  
  441.          For a copy of the latest monthly software library newsletter
  442.          and a list of the 1,900+ disks in the library, call or write
  443.  
  444.                         The Public (Software) Library
  445.                               P.O.Box 35705 - F
  446.                            Houston, TX 77235-5705
  447.                                (713) 665-7017
  448.  
  449.